package com.openbravo.beans;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;

public class JCalendarDialog extends JDialog
{
  private static LocaleResources m_resources;
  private Date m_date;
  private JCalendarPanel myCalendar = null;
  private JTimePanel myTime = null;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JPanel jPanelGrid;
  private JButton jcmdCancel;
  private JButton jcmdOK;

  public JCalendarDialog(Frame paramFrame, boolean paramBoolean)
  {
    super(paramFrame, paramBoolean);
    if (m_resources == null)
    {
      m_resources = new LocaleResources();
      m_resources.addBundleName("beans_messages");
    }
  }

  public JCalendarDialog(Dialog paramDialog, boolean paramBoolean)
  {
    super(paramDialog, paramBoolean);
    if (m_resources == null)
    {
      m_resources = new LocaleResources();
      m_resources.addBundleName("beans_messages");
    }
  }

  private static Window getWindow(Component paramComponent)
  {
    if (paramComponent == null)
      return new JFrame();
    if (((paramComponent instanceof Frame)) || ((paramComponent instanceof Dialog)))
      return (Window)paramComponent;
    return getWindow(paramComponent.getParent());
  }

  public static Date showCalendarTimeHours(Component paramComponent, Date paramDate)
  {
    return internalCalendarTime(paramComponent, paramDate == null ? DateUtils.getToday() : paramDate, true);
  }

  public static Date showCalendarTime(Component paramComponent, Date paramDate)
  {
    return internalCalendarTime(paramComponent, paramDate == null ? DateUtils.getTodayMinutes() : paramDate, true);
  }

  public static Date showCalendar(Component paramComponent, Date paramDate)
  {
    return internalCalendarTime(paramComponent, paramDate == null ? DateUtils.getTodayMinutes() : paramDate, false);
  }

  private static Date internalCalendarTime(Component paramComponent, Date paramDate, boolean paramBoolean)
  {
    Window localWindow = getWindow(paramComponent);
    JCalendarDialog localJCalendarDialog;
    if ((localWindow instanceof Frame))
      localJCalendarDialog = new JCalendarDialog((Frame)localWindow, true);
    else
      localJCalendarDialog = new JCalendarDialog((Dialog)localWindow, true);
    localJCalendarDialog.initComponents();
    Date localDate = paramDate;
    int i = 400;
    localJCalendarDialog.myCalendar = new JCalendarPanel(localDate);
    localJCalendarDialog.myCalendar.addPropertyChangeListener("Date", new JPanelCalendarChange(localJCalendarDialog));
    localJCalendarDialog.jPanelGrid.add(localJCalendarDialog.myCalendar);
    if (paramBoolean)
    {
      localJCalendarDialog.myTime = new JTimePanel(localDate);
      localJCalendarDialog.myTime.addPropertyChangeListener("Date", new JPanelTimeChange(localJCalendarDialog));
      localJCalendarDialog.jPanelGrid.add(localJCalendarDialog.myTime);
      i += 400;
    }
    localJCalendarDialog.getRootPane().setDefaultButton(localJCalendarDialog.jcmdOK);
    Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
    localJCalendarDialog.setBounds((localDimension.width - i) / 2, (localDimension.height - 359) / 2, i, 359);
    localJCalendarDialog.m_date = null;
    localJCalendarDialog.setVisible(true);
    return localJCalendarDialog.m_date;
  }

  private void initComponents()
  {
    this.jPanel1 = new JPanel();
    this.jcmdOK = new JButton();
    this.jcmdCancel = new JButton();
    this.jPanel2 = new JPanel();
    this.jPanelGrid = new JPanel();
    setTitle(m_resources.getString("title.calendar"));
    setResizable(false);
    addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent paramWindowEvent)
      {
        JCalendarDialog.this.closeWindow(paramWindowEvent);
      }
    });
    this.jPanel1.setLayout(new FlowLayout(2));
    this.jcmdOK.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png")));
    this.jcmdOK.setText(m_resources.getString("button.ok"));
    this.jcmdOK.setMargin(new Insets(8, 16, 8, 16));
    this.jcmdOK.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JCalendarDialog.this.jcmdOKActionPerformed(paramActionEvent);
      }
    });
    this.jPanel1.add(this.jcmdOK);
    this.jcmdCancel.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png")));
    this.jcmdCancel.setText(m_resources.getString("button.cancel"));
    this.jcmdCancel.setMargin(new Insets(8, 16, 8, 16));
    this.jcmdCancel.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JCalendarDialog.this.jcmdCancelActionPerformed(paramActionEvent);
      }
    });
    this.jPanel1.add(this.jcmdCancel);
    getContentPane().add(this.jPanel1, "South");
    this.jPanel2.setLayout(new BorderLayout());
    this.jPanel2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.jPanelGrid.setLayout(new GridLayout(1, 0, 5, 0));
    this.jPanel2.add(this.jPanelGrid, "Center");
    getContentPane().add(this.jPanel2, "Center");
  }

  private void jcmdOKActionPerformed(ActionEvent paramActionEvent)
  {
    GregorianCalendar localGregorianCalendar2 = new GregorianCalendar();
    localGregorianCalendar2.setTime(this.myCalendar.getDate());
    GregorianCalendar localGregorianCalendar1;
    if (this.myTime == null)
    {
      localGregorianCalendar1 = new GregorianCalendar(localGregorianCalendar2.get(1), localGregorianCalendar2.get(2), localGregorianCalendar2.get(5));
    }
    else
    {
      GregorianCalendar localGregorianCalendar3 = new GregorianCalendar();
      localGregorianCalendar3.setTime(this.myTime.getDate());
      localGregorianCalendar1 = new GregorianCalendar(localGregorianCalendar2.get(1), localGregorianCalendar2.get(2), localGregorianCalendar2.get(5), localGregorianCalendar3.get(11), localGregorianCalendar3.get(12));
    }
    this.m_date = localGregorianCalendar1.getTime();
    setVisible(false);
    dispose();
  }

  private void jcmdCancelActionPerformed(ActionEvent paramActionEvent)
  {
    setVisible(false);
    dispose();
  }

  private void closeWindow(WindowEvent paramWindowEvent)
  {
    setVisible(false);
    dispose();
  }

  private static class JPanelCalendarChange
    implements PropertyChangeListener
  {
    private JCalendarDialog m_me;

    public JPanelCalendarChange(JCalendarDialog paramJCalendarDialog)
    {
      this.m_me = paramJCalendarDialog;
    }

    public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
    {
      this.m_me.myTime.setDate(this.m_me.myCalendar.getDate());
    }
  }

  private static class JPanelTimeChange
    implements PropertyChangeListener
  {
    private JCalendarDialog m_me;

    public JPanelTimeChange(JCalendarDialog paramJCalendarDialog)
    {
      this.m_me = paramJCalendarDialog;
    }

    public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
    {
      this.m_me.myCalendar.setDate(this.m_me.myTime.getDate());
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.beans.JCalendarDialog
 * JD-Core Version:    0.6.0
 */